<template>
  <div style="min=width:1366px">
    <!-- 搜索栏区域 -->
    <el-card class="SearchCard" body-style="padding:0px">
      <el-row>
        <el-col :span="2">
          <div class="SearchTitle">条件搜索栏</div>
        </el-col>
        <el-col :span="4">
          <el-row>
            <el-col :span="10">
              <div class="SearchLable">搜索关键字</div>
            </el-col>

            <el-col :span="14">
              <div class="SearchLable">
                <el-input placeholder="请输入内容" v-model="queryInfo.srm" clearable @clear="clearEvent"></el-input>
              </div>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="2">
          <div class="SearchLable">
            <el-button size="medium" type="primary" @click="getSearchList()">搜索</el-button>
          </div>
        </el-col>
        <el-col :span="2">
          <div class="SearchLable">
            <el-button size="medium" @click="showUrl()" type="primary">添加图片</el-button>
          </div>
        </el-col>
      </el-row>
    </el-card>
    <el-card class="TableCard" :body-style="{ padding: '0px' }">
      <div>
        <el-table
          :data="tableData"
          border
          :header-cell-style="{ 'text-align':'center',background: '#3F9DFD', color: '#FFF' }"
          :cell-style="{'text-align':'center'}"
          size="medium"
          stripe
          style="width: 100%;font-size:12px"
        >
          <el-table-column type="index" width="50"></el-table-column>
          <el-table-column prop="drugCode" label="药品编码" width="100"></el-table-column>
          <el-table-column prop="name" label="操作" width="60">
            <template slot-scope="scope">
              <el-button
                type="text"
                size="mini"
                v-if="scope.row.count==0"
                @click="addPicture(scope.row.drugCode,scope.row.drugName)"
              >添加</el-button>
              <el-button type="text" size="mini" v-else @click="showPicture(scope.row.drugCode)">查看</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="drugName" label="药品名称"></el-table-column>
          <el-table-column label="药品类型" width="80">
            <template slot-scope="scope">
              <div v-if="scope.row.nameType==8">西药</div>
              <div v-else-if="scope.row.nameType==2">草药</div>
              <div v-else-if="scope.row.nameType==6">中成药</div>
            </template>
          </el-table-column>
          <el-table-column prop="doseUnit" label="给药单位"></el-table-column>
          <el-table-column prop="compName" label="药品生产厂家"></el-table-column>
          <el-table-column prop="approvalCode" label="批准文号"></el-table-column>
          <el-table-column prop="doseUnit" label="给药单位"></el-table-column>
        </el-table>
      </div>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[20, 50, 100]"
          :page-size="queryInfo.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="this.total"
          background
        ></el-pagination>
      </div>
    </el-card>
    <el-dialog
      :title="'上传外包装图片'+'—'+addPictureData.drugName"
      :visible.sync="showOuterPackVisible"
      width="45%"
      :before-close="handleClose"
    >
      <el-upload
        name="file"
        :action="uploadUrl"
        list-type="picture-card"
        :on-preview="handlePictureCardPreview"
        :on-remove="handleRemove"
        :data="{drugCode:addPictureData.drugCode}"
      >
        <i class="el-icon-plus"></i>
      </el-upload>
      <el-dialog :visible.sync="dialogVisible">
        <img width="100%" :src="dialogImageUrl" alt />
      </el-dialog>
      <span slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="jumpHtml()">使用高拍仪</el-button> -->
        <el-button type="primary" @click="showOuterPackVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="提示"
      :visible.sync="showPictureVisible"
      width="30%"
      :before-close="handleClose"
    >
      <!-- <div class="demo-image__preview">
        <el-image style="width: 100px; height: 100px"
                  :src="url"
                  :preview-src-list="srcList">
        </el-image>
      </div>-->
      <span slot="footer" class="dialog-footer">
        <el-button @click="showPictureVisible = false">取 消</el-button>
        <!-- <a href="lcmedi-web\src\views\rad\radSystemInfo\OuterPack\jieyudemo\index.html">W3School</a> -->
        <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { getOutPictureList, LoadOutPicture } from "@/api/rad";
import { rad } from "@/api/systemport";
export default {
  data() {
    return {
      queryInfo: {
        srm: "",
        page: 1,
        pageSize: 20,
      },
      total: 0,
      tableData: [],
      showOuterPackVisible: false,
      dialogImageUrl: "",
      dialogVisible: false,
      addPictureData: {
        drugCode: "",
        drugName: "",
      },
      uploadUrl: "",
      showPictureVisible: false,
    };
  },
  created: function () {
    this.getOutPictureList();
    this.uploadUrl =
      process.env.VUE_APP_BASE_API +
      ":" +
      rad +
      "/core/sys/Information/uploadOutPicture";
    console.log(this.uploadUrl);
  },
  methods: {
    jumpHtml() {
      window.open(
        "/rad/radSystemInfo/OuterPack/jieyudemo/index.html",
        "_blank"
      );
    },
    handleClose(done) {
      done();
    },
    handleSizeChange(newSize) {
      this.queryInfo.pageSize = newSize;
      this.getOutPictureList();
    },

    handleCurrentChange(newPage) {
      this.queryInfo.page = newPage;
      this.getOutPictureList();
    },

    getSearchList() {
      this.getOutPictureList();
    },
    clearEvent() {
      this.getOutPictureList();
    },
    async getOutPictureList() {
      let res = await this.$rad.getOutPictureList({
        srm: this.queryInfo.srm,
        page: this.queryInfo.page,
        pageSize: this.queryInfo.pageSize,
      });
      this.tableData = res.rows;
      this.total = res.total;
      console.log(res);
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    addPicture(drugCode, drugName) {
      this.showOuterPackVisible = true;
      this.addPictureData.drugCode = drugCode;
      this.addPictureData.drugName = drugName;
    },
    showUrl() {
      console.log(process.env.VUE_APP_BASE_API + ":" + rad);
    },
    async showPicture(drugCode) {
      this.showPictureVisible = true;
      let res = await this.$rad.LoadOutPicture({
        drugCode: drugCode,
      });
      console.log(res);
    },
  },
};
</script>
<style>
.SearchCard {
  height: 50px;
  font-size: 12px;
}
.SearchTitle {
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-right: 1px solid #c2c2c2;
}
.SearchLable {
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.TableCard {
  margin-left: 3px;
  margin-top: 2px;
}
.block {
  text-align: center;
  margin-top: 12px;
  margin-bottom: 12px;
}
</style>